<template>
  <el-form :model="form" label-width="120px">
 
        <JmInput
          jmname="用户名"
          v-model="form.username"
          placeholder="sad"
          type="text"
        ></JmInput>
        <JmInput
          jmname="邮箱"
          v-model="form.email"
          placeholder="sad"
          type="text"
        ></JmInput> 
        
        <JmInput
          jmname="昵称"
          v-model="form.nickname"
          placeholder="sad"
          remark="备注" 
          type="text"
        ></JmInput>
        <JmInput
          jmname="密码"
          v-model="form.password"
          placeholder="sad"
          remark="备注"
          type="text"
        ></JmInput> 
<JmEnum
          jmname="状态"
          v-model="form.status"
          :jv="{ 1: '是', 0: '否' }"
          jtype="3"
          br
        ></JmEnum>
  <el-form-item  label="所属组别"> 
  <el-select v-model="form.group_id" placeholder="Select">
    <el-option
      v-for="item in cities"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    >
      <span style="float: left">{{ item.label }}</span>
      <span
        style="
          float: right;
          color: var(--el-text-color-secondary);
          font-size: 13px;
        "
        >{{ item.value }}</span
      >
    </el-option>
  </el-select>  
  </el-form-item>
 

      <el-form-item>
        <el-button type="primary" @click="onSubmit">Create</el-button>
        <el-button>Cancel</el-button>
      </el-form-item>
 
  </el-form>
</template>
 
<script>
import JmInput from "../../../components/form/JmInput.vue";
import JmEnum from "../../../components/form/JmEnum.vue";
export default {
  components: { JmInput, JmEnum },
  data() {
    return {
         form: {
                username: '',
                nickname: "",
                password: "",
                avatar: '',
                group_id:"",
                status:'',
            },

      cities :[
               
            ]
    };
  },
//在export default中添加即可不用管顺序
    watch: {
       //监听内容
       edit_id() {
        console.log("edit_id发生了变化");
        this.getDataList();
      }
    },
    props: ['edit_id'],
     inject:['handleClose'],
     
  mounted() {
    this.getDataList();
  },
  methods: {
    // 配置信息列表初始化
    async getDataList() {
      try {
        const res = await this.$api.getGroup(); 
        let ccc=[];
       
      res.rows.forEach(element => {
         let cccz=[];
         cccz["value"]=element.id;
         cccz["label"]=element.name;
         ccc.push(cccz);  
      });
       
         this.cities=ccc;
   /*查看单条数据*/
        const find = await this.$api.editAdminFind({ids:this.edit_id}); 
        this.form.username=find.username;
        this.form.nickname=find.nickname;
        // this.form.password=find.password;
        this.form.avatar=find.avatar;
        this.form.group_id=find.group_id;
        this.form.status=find.status;
        
      } catch (error) {
        /*console.error(error);*/
      }
    },
     async onSubmit() {
       const find =  await this.$api.editAdmin(this.form,this.edit_id);  
     
       this.$parent.$parent.$parent.$parent.handleClose();
            //  this.$parent.handleClose();
            // this.$emit("handleClose","如果需要传值，参数写在这里"); 
    },
  },
};
 
</script>